package com.ruoyi.web.controller.employee;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.employee.domain.HrPersonChangeView;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.HrPersonChange;
import com.ruoyi.employee.service.IHrPersonChangeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员变动记录Controller
 * author hango
 * date 2025-10-19
 */
@RestController
@RequestMapping("/employee/person_change")
public class HrPersonChangeController extends BaseController
{
    @Autowired
    private IHrPersonChangeService hrPersonChangeService;

    /**
     * 查询人员变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrPersonChange hrPersonChange)
    {
        startPage(); // 使用 pageNum/pageSize 分页
        List<HrPersonChange> list = hrPersonChangeService.selectHrPersonChangeList(hrPersonChange);
        return getDataTable(list);
    }

    /**
     * 导出人员变动记录列表
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:export')")
    @Log(title = "人员变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrPersonChange hrPersonChange)
    {
        List<HrPersonChange> list = hrPersonChangeService.selectHrPersonChangeList(hrPersonChange);
        ExcelUtil<HrPersonChange> util = new ExcelUtil<HrPersonChange>(HrPersonChange.class);
        util.exportExcel(response, list, "人员变动记录数据");
    }

    /**
     * 获取人员变动记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(hrPersonChangeService.selectHrPersonChangeById(id));
    }

    /**
     * 新增人员变动记录
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:add')")
    @Log(title = "人员变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HrPersonChange hrPersonChange)
    {
        return toAjax(hrPersonChangeService.insertHrPersonChange(hrPersonChange));
    }

    /**
     * 修改人员变动记录
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:edit')")
    @Log(title = "人员变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HrPersonChange hrPersonChange)
    {
        return toAjax(hrPersonChangeService.updateHrPersonChange(hrPersonChange));
    }

    /**
     * 删除人员变动记录
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:remove')")
    @Log(title = "人员变动记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hrPersonChangeService.deleteHrPersonChangeByIds(ids));
    }




    /**
     * 获取人员变动记录详细信息（视图）
     * 说明：从 vw_hr_person_change 视图按主键查询单条记录。
     */
    @PreAuthorize("@ss.hasPermi('employee:person_change:query')")
    @GetMapping("/view/{id}")
    public AjaxResult getViewInfo(@PathVariable("id") String id)
    {
        return success(hrPersonChangeService.selectOneFromView(id));
    }


    /**
     * 查询人员变动记录列表（视图）
     * 说明：从 vw_hr_person_change 视图查询，返回带部门/岗位/职级名称与可读文案。
     * 支持参数：empId、beginTime、endTime（均可空）；分页依赖 pageNum/pageSize。
     */

    @PreAuthorize("@ss.hasPermi('employee:person_change:list')")
    @GetMapping("/view/list")
    public TableDataInfo viewList(HrPersonChange query) {
        startPage(); // 由 pageNum/pageSize 控制动态分页
        // 前端可直接传 empId、params[beginTime]、params[endTime]
        List<HrPersonChangeView> list = hrPersonChangeService.selectHrPersonChangeViewList(query);
        return getDataTable(list);
    }
}
